package com.dis.service.controller.admin;

import com.dis.common.annotation.CheckPermission;
import com.dis.pojo.vo.HospitalVO;
import com.dis.pojo.dto.HospitalDTO;
import com.dis.pojo.queryDTO.HospitalPageQueryDTO;
import com.dis.common.result.PageResult;
import com.dis.common.result.Result;
import com.dis.service.service.HospitalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/hospital")
@Api(tags = "医院管理")
@Slf4j
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;

    @PostMapping
    @ApiOperation("新增医院")
    @CheckPermission("hospital:add")
    public Result save(@RequestBody HospitalDTO hospitalDTO) {
        hospitalService.save(hospitalDTO);
        return Result.success();
    }

    @GetMapping("/page")
    @ApiOperation("分页查询医院")
    @CheckPermission("hospital:query")
    public Result<PageResult> page(HospitalPageQueryDTO hospitalPageQueryDTO) {
        PageResult pageResult = hospitalService.pageQuery(hospitalPageQueryDTO);
        return Result.success(pageResult);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID查询医院")
    @CheckPermission("hospital:query")
    public Result<HospitalVO> getById(@PathVariable Long id) {
        HospitalVO hospitalVO = hospitalService.getById(id);
        return Result.success(hospitalVO);
    }

    @PutMapping
    @ApiOperation("更新医院")
    @CheckPermission("hospital:edit")
    public Result update(@RequestBody HospitalDTO hospitalDTO) {
        hospitalService.update(hospitalDTO);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除医院")
    @CheckPermission("hospital:delete")
    public Result delete(@PathVariable Long id) {
        hospitalService.deleteById(id);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation("获取所有医院列表")
    @CheckPermission("hospital:query")
    public Result<List<HospitalVO>> listAll() {
        List<HospitalVO> hospitals = hospitalService.listAll();
        return Result.success(hospitals);
    }
}
